<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var subsets = function (nums) {
      const ans = [];
      const n = nums.length;
      for (let mask = 0; mask < (1 << n); ++mask) {
        const t = [];
        for (let i = 0; i < n; ++i) {
          if (mask & (1 << i)) {
            t.push(nums[i]);
          }
        }
        ans.push(t);
      }
      return ans;
    };
    console.log(subsets([1, 2, 3]));
  </script>
</body>

</html>